﻿/*  
 *  IIS LogFile Analyser, Copyright (C) 2013. http://www.iis-analyser.com
 *  --
 *  This program is free software, provided "AS IS" WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
 * 
 *  File Author: Ian Quigley,    2013-02-23
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using Web.Common;
using System.Globalization;

namespace Web.Filter
{
    public class FilterString : IFilterView
    {
        public string Name
        {
            get { return "Filter String"; }
        }

        public void BuildHtml(StringBuilder html, string sqlColumn)
        {
            html.Append( "<td align='right' width='20%'><b>String</b></td><td width='80%'><div data-sqlcolumn='" + sqlColumn + "' data-filtertype='FilterString'>" +
                "<input type='text' class='filterChange' id='text' />" +
                "</div></td>");
        }


        public string UpdateSql( string sql, FilterItem item )
        {
            if (string.IsNullOrWhiteSpace( item.Data) )
                return sql;

            
            return sql.Replace( "{" + item.SqlColumn + "}", string.Format( "{0} like '{1}' ", item.SqlColumn, item.Data), StringComparison.OrdinalIgnoreCase );
        }
    }
}